package com.hm.shopping.web.tourists;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hm.common.annotation.WebClientRequestIntercept;
import com.hm.common.util.EncryptUtil.Base64;
import com.hm.shopping.auto.SystemEnvConfigProperties;
import com.hm.shopping.auto.su.R.Uri;
import com.hm.shopping.auto.su.helper.HmSessionFactory;
import com.hm.shopping.service.NewsAnnouncementService;
import com.hm.shopping.service.ShopcartService;

/**
 * @author shishun.wang
 * @date 2018年1月24日 下午3:08:10
 * @version 1.0
 * @describe 新闻公告
 */
@Controller
@RequestMapping(Uri.PC + "/newsAnnouncement")
public class NewsAnnouncementController {
	
	@Autowired
	private ShopcartService shopcartService;
	
	@Autowired
	private NewsAnnouncementService newsAnnouncementService;

	@Autowired
	private SystemEnvConfigProperties systemEnvConfigProperties;
	
	@WebClientRequestIntercept(auth = false)
	@RequestMapping(value = "newsBlog.do", method = RequestMethod.GET)
	public String getNewsAnnouncement(Model model, String newsAnnouncementId) {
		model.addAttribute("article", newsAnnouncementService.getNewsAnnouncement(newsAnnouncementId));
		model.addAttribute("hotArticles", newsAnnouncementService.getTopNewsAnnouncement());
		model.addAttribute("copyrightStatement", new String(Base64.decode(systemEnvConfigProperties.getFooterCopyrightStatementPC().toCharArray())));//版权信息
		try {
			model.addAttribute("shopcartGoodsCount", shopcartService.getShopcartGoodsCount(HmSessionFactory.currentUserIdString()));
		}catch(Exception e) {
			model.addAttribute("shopcartGoodsCount", shopcartService.getShopcartGoodsCount(null));
		}
		return "news-blog";
	}
}
